{% extends "my/layout.html" %}

{% block my %}
<div class="container">
    {% if cart_items %}
    <table class="table order-cart">
        <tr>
            <th>#</th>
            <th>名称</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>

        {% for item in shopping_cart %}
        <tr>
            <td>{{loop.index}}</td>
            <td>{{item.name}}</td>
            <td>{{item.created}}</td>
            <td><a href="#" data-value="{{item.id}}">X</a></td>
        </tr>
        {% endfor %}
    </table>

    <form action="{{url_for('over.handlers.my.order.pay')}}" method="post" class="form-horizontal">
        <button  class="btn btn-success">付款</button>
    </form>

    {% endif %}
</div>

{% endblock %}

{% block script %}
<script type="text/javascript">
    $(function () {
        $(".order-cart a").click(function () {
            var $this = $(this);
            var id = $this.attr('data-value');

            $.post('{{url_for("over.handlers.my.order.remove_cart_item")}}', {'cart_item_id': id}, function(data){
                if(!data.success){
                    alert(data.msg);
                }else{
                    window.location = "{{url_for('over.handlers.my.order.cart')}}";
                }
            });
        });

    });
</script>

{% endblock %}
